package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * 操作类型枚举，用于日志记录
 * 来着 SAAS 项目
 * @author feng.zheng
 * @since v1.0
 */
@Getter
public enum OperatePageEnum {
	/**
	 * 操作枚举，用于记录日志
	 */
	NEW(1, "enum.operatePage.name.new", "new"),

	EDIT(2, "enum.operatePage.name.edit", "edit"),

	LIST(3, "enum.operatePage.name.list", "list"),

	IMPORT(4,"enum.operatePage.name.import","import"),

	EXPORT(5,"enum.operatePage.name.export","export"),

	DETAIL(6,"enum.operatePage.name.detail","detail"),

	DESIGN(7,"enum.operatePage.name.design","design"),

	UNKNOWN(404, "enum.operatePage.name.unknown", "unknown");

	/** 枚举值 -- 操作类型标识*/
	private final int	 code;

	/** 枚举信息--操作名称*/
	private final String name;

	/** 枚举描述 --角色使用时状态*/
	private final String alias;

	/**
	 * 构造一个<code>OperateTypeEnum</code>枚举对象
	 *
	 * @param code 操作码
	 * @param name 操作名称
	 * @param alias 操作别名
	 */
	OperatePageEnum(int code, String name, String alias) {
		this.code = code;
		this.name = name;
		this.alias = alias;
	}
	
	/**
	 * 通过枚举<code>alias</code>获得枚举
	 *
	 * @param alias 操作别名
	 * @return OperateTypeEnum
	 */
	public static OperatePageEnum getByAlias(String alias) {
		for (OperatePageEnum cacheCode : values()) {
			if (cacheCode.getAlias().equals(alias)) {
				return cacheCode;
			}
		}
		return UNKNOWN;
	}
	
	/**
	 * 通过枚举<code>code</code>获得枚举
	 *
	 * @param code 操作码
	 * @return OperateTypeEnum
	 */
	public static OperatePageEnum getByCode(Integer code) {
		for (OperatePageEnum cacheCode : values()) {
			if (code.equals(cacheCode.getCode())) {
				return cacheCode;
			}
		}
		return UNKNOWN;
	}
	
	/**
	 * 获取全部枚举
	 * 
	 * @return List<OperateTypeEnum>
	 */
	public static List<OperatePageEnum> getAllEnum() {
		List<OperatePageEnum> list = new ArrayList<>();
		for (OperatePageEnum cache : values()) {
			if (cache == UNKNOWN) {
				continue;
			}
			list.add(cache);
		}
		return list;
	}
	
	/**
	 * 获取全部枚举值
	 * 
	 * @return List<String>
	 */
	public static List<String> getAllEnumAlis() {
		List<String> list = new ArrayList<>();
		for (OperatePageEnum cache : values()) {
			if (cache == UNKNOWN) {
				continue;
			}
			list.add(cache.getAlias());
		}
		return list;
	}

	public String getName() {
		return I18nMessageUtil.getMessage(name);
	}
}
